#include <iostream>
using std::cout;
using std::endl;

/* int count = 0; */

class FunctionObject
{
public:
    //第一个()是和operator连着一起作为函数名
    //代表对函数调用运算符进行重载
    //第二个()是参数列表
    void operator()(){
        ++_count;
        cout << "operator()()函数被调用" << endl;
    }

    void operator()(int x){
        ++_count;
        cout << "operator()(int)函数被调用 " << x << endl;
    }

    int operator()(int x,int y){
        ++_count;
        cout << "operator()(int,int)函数被调用 " << endl;
        return x + y;
    }

    int getCount() const{
        return _count;
    }
private:
    int _count = 0;
};

int print(int x,int y){
    return x + y;
}

void print(int x){
    cout << "print(int):" << x << endl;
}

void print(){
    static int count = 0;
    ++count;
    cout << "print()" << endl;
}

void test0(){
    print();
    print();
    print();
    print();
    /* count = 0; */
    /* cout << "count:" << count << endl; */
    print(5);
    cout << print(3,4) << endl;

    cout << endl;
    FunctionObject fo;
    //希望让对象像函数一样进行调用
    fo();
    /* fo.operator()();//本质 */
    fo(8);
    cout << fo(5,6) << endl;

    //查看fo对象被作为函数对象调用了几次
    //函数对象可以携带状态（相比于普通函数的优势）
    /* cout << fo._count << endl; */
    cout << fo.getCount() << endl;
}

int main(void){
    test0();
    return 0;
}
